package edu.gdit.health.springIOC;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect//声明增强
public class MyAdvice {
    //说明before方法前置方法，（）内参数声明切点，
    // *表示切在所有方法上；(..)便是任意参数个数)
//    @Before("execution(* edu.gdit.health.springIOC.MyMath.*(..))")
    @Before("execution(* edu.gdit.health.springIOC.MyMath.a*(..))")
    public void before(){
        System.out.println(">>>>>>>>>>>>我是一个前置方法<<<<<<<<<<<<");
    }
    //说明after方法后置方法，（）内参数声明切点，
    // *表示切在所有方法上；(..)便是任意参数个数)
//    @After("execution(* edu.gdit.health.springIOC.MyMath.*(..))")
    @After("execution(* edu.gdit.health.springIOC.MyMath.s*(..))")
    public void after(){
        System.out.println(">>>>>>>>>>>>我是一个后置方法<<<<<<<<<<<<");
    }

    @Around("execution(* edu.gdit.health.springIOC.MyMath.m*(..))")

    public void around(ProceedingJoinPoint point) throws Throwable{
        System.out.println(">>>>>>>>>>>>方法执行前<<<<<<<<<<<<");
        try {
            point.proceed();
            System.out.println(">>>>>>>>>>>>方法执行后<<<<<<<<<<<<");
        }catch (Exception e){
            System.out.println(">>>>>>>>>>>>异常抛出<<<<<<<<<<<<");
            e.printStackTrace();
        }
    }
    @Around("execution(* edu.gdit.health.springIOC.MyMath.d*(..))")
    public void around1(ProceedingJoinPoint point) throws Throwable{
        System.out.println(">>>>>>>>>>>>执行方法前d<<<<<<<<<<<<");
        try {
            point.proceed();
            System.out.println(">>>>>>>>>>>>执行方法后d<<<<<<<<<<<<");
        }catch (Exception e){
            System.out.println(">>>>>>>>>>>>异常抛出<<<<<<<<<<<<");
            e.printStackTrace();
        }
    }
}
